package com.jgp.glmeeting.controller;

import com.jgp.glmeeting.model.Meeting;
import com.jgp.glmeeting.service.MeetingService;
import com.jgp.sys.common.controller.JGPController;
import com.jgp.sys.ui.GridResult;
import com.jgp.sys.ui.Pager;
import com.jgp.sys.ui.Result;
import com.jgp.sys.ui.annotation.UIParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/glMeeting/meetingApiController")
public class MeetingApiController extends JGPController {
    @Autowired
    private MeetingService meetingService;


    //添加会议
    @RequestMapping("/addMeeting")
    public Result addMeeting(Meeting m){
        meetingService.addMeeting(m);
        return ajaxRe(true);
    }

    //处理会议所有和分页
    @RequestMapping("/queryMeetings")
    public Result queryMeetings(Meeting m,@UIParam("pager") Pager pager){
        List<Meeting>lists=meetingService.queryMeetings(m,pager);
        List<GridResult.Category> categories = new ArrayList<>();
        categories.add(new GridResult.Category(  "会议名称",  "name"));
        categories.add(new GridResult.Category("会议开始时间",  "startDate"));
        categories.add(new GridResult.Category("会议结束时间",  "endDate"));
        categories.add(new GridResult.Category("主办方",  "zbf"));
        return ajaxRe("gdata",categories,lists,pager);
    }

    //会议删除
    @RequestMapping("/removeMeeting")
    public Result removeMeeting(String id){
        if(StringUtils.isBlank(id)){
            return ajaxRe(false);
        }
        meetingService.removeMeeting(id);
        return ajaxRe(true);
    }

}
